package zhihuilan.config;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Base64;


@Configuration
@Component
@Data
public class WeChatPayMiniConfig {

    private String appId;
    private String mchId;
    private String serialNo;
    private String apiV3Key;
    private String notifyUrl;
    private String certPath;

    public static final Integer ORDER_PAY_TIME_OUT = 1440;

    private Config config;

    public WeChatPayMiniConfig() {

    }

    @Value("${wx.miniapp.appId}")
    public void setAppId(String appId) {
        this.appId = appId;
    }

    @Value("${wx.pay.mchId}")
    public void setMchId(String mchId) {
        this.mchId = mchId;
    }

    @Value("${wx.pay.mchSerialNo}")
    public void setSerialNo(String serialNo) {
        this.serialNo = serialNo;
    }

    @Value("${wx.pay.v3Key}")
    public void setApiV3Key(String apiV3Key) {
        this.apiV3Key = apiV3Key;
    }

    @Value("${wx.pay.notifyUrl}")
    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    @Value("${wx.pay.sslKey}")
    public void setCertPath(String certPath) {
        this.certPath = certPath;
    }

//    @PostConstruct
    public void init() {
        this.config = new RSAAutoCertificateConfig.Builder()
                .merchantId(mchId)
                .privateKey(certPath)
                .merchantSerialNumber(serialNo)
                .apiV3Key(apiV3Key)
                .build();
    }



}